package swu.edu.cn.javaee.controller;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import swu.edu.cn.javaee.entity.Friend;
import swu.edu.cn.javaee.service.FriendService;

import java.lang.reflect.Field;
import java.util.List;

@Controller
public class FriendController {

    @Resource
    private FriendService friendService;

    @RequestMapping("/queryAllFriend")
    @ResponseBody
    public List<Friend> queryAllFriend(String userId){
        List<Friend> list=friendService.queryAllFriend(userId);
        if(list!=null){
            return list;
        }
        else {
            return null;
        }
    }

    /**
     * 查询请求（按组区分）
     * */
    @RequestMapping("/queryByUserGroup")
    @ResponseBody
    public List<Friend> queryFriendByUserGroup(String userGroup){
        List<Friend> list=friendService.queryFriendByUserGroup(userGroup);
        if(list.size()!=0){
            return list;
        }
        return null;
    }
    /**
     * 添加好友请求
     * */
    @RequestMapping("/saveFriend")
    @ResponseBody
    public String saveFriend(Friend friend){
        String result=friendService.saveFriend(friend);
        return result;
    }
    /**
     * 修改好友分组
     * */
    @RequestMapping("/changeGroup")
    @ResponseBody
    public String changeGroup(Friend friend){
        String result=friendService.updateFriend(friend);
        return result;
    }

    /**
     * 删除好友
     * */
    @RequestMapping("/deleteFriend")
    @ResponseBody
    public String deleteFriend(Friend friend){
        String result=friendService.deleteFriend(friend);
        return result;
    }
}
